import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { HttpClient } from '@angular/common/http';
import { BoardGroupVo } from '../model/board-group-vo';
import { BoardGroupCollectVo } from '../model/board-group-collect-vo';
import { EMPTY, throwError, Observable } from 'rxjs';
@Injectable({
  providedIn: 'root'
})
export class BoardGroupService {
  private restRequestURI: string = environment.restURI + '/boardgroup';
  /**
   * 版块组REST API服务
   */
  constructor(private http: HttpClient) { }

  /**
   * 查看指定的版块组
   * @param boardGroupId 版块组ID
   */
  public get(boardGroupId: number): Observable<BoardGroupVo> {
    if (0 >= boardGroupId) {
      return throwError('版块组ID非可用值');
    }
    return this.http.get<BoardGroupVo>(this.restRequestURI + '/' + boardGroupId);
  }
  /**
   * 查看所有的版块组,级联加载其下的版块
   * @param containDefaultBoard 是否显示默认版块组,默认为true包含
   */
  public getAll(containDefaultBoard: boolean = true): Observable<BoardGroupCollectVo[]> {
    let cdval: number = containDefaultBoard ? 1 : 0;
    return this.http.get<BoardGroupCollectVo[]>(this.restRequestURI + '/all/cascade/' + cdval);
  }
  /**
   * 查看指定的版块组,级联加载其下的版块
   * @param boardGroupId 版块组ID
   */
  public getCascadeUsedBoard(boardGroupId: number): Observable<BoardGroupCollectVo> {
    if (0 >= boardGroupId) {
      return throwError('版块组ID非可用值');
    }
    return this.http.get<BoardGroupCollectVo>(this.restRequestURI + '/' + boardGroupId + '/cascade');
  }
  /**
   * 查看所有可用的版块组
   */
  public getAllUsed(): Observable<BoardGroupVo[]> {
    //:/all
    return this.http.get<BoardGroupVo[]>(this.restRequestURI + '/all');
  }
}
